package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.Goods;
import com.atguigu.gmall.search.service.GoodsService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lfy
 * @Description
 * @create 2023-08-26 8:42
 */
@RequestMapping("/api/inner/search")
@RestController
public class SearchRpcController {


    @Autowired
    GoodsService goodsService;


    /**
     *
     * @param skuId  商品id
     * @param score  最新热度分
     * @return
     */
    @GetMapping("/incrhotscore/{skuId}/{score}")
    public Result incrHotScore(@PathVariable("skuId") Long skuId,
                               @PathVariable("score") Long score){

        goodsService.updateHotScore(skuId,score);
        return Result.ok();
    }

    @PostMapping("/search")
    public Result<SearchResultVo> search(@RequestBody SearchParamVo searchParam){
        //检索
        SearchResultVo resultVo = goodsService.search(searchParam);
        return Result.ok(resultVo);
    }


    /**
     * 商品下架
     * @param skuId
     * @return
     */
    @DeleteMapping("/goods/{skuId}")
    public Result delete(@PathVariable("skuId") Long skuId){
        goodsService.deleteById(skuId);
        return Result.ok();
    }

    /**
     * 保存 商品数据 到 ES
     * @param goods
     * @return
     */
    @PostMapping("/save")
    public Result saveGoods(@RequestBody Goods goods){


        goodsService.save(goods);

        return Result.ok();
    }
}
